<body>
<p>Test Worker.terminate().</p>
<div id=result></div>
<script src="../../resources/gc.js"></script>
<script>
function log(message)
{
    document.getElementById("result").innerHTML += message + "<br>";
}

if (window.testRunner) {
    testRunner.dumpAsText();
    testRunner.waitUntilDone();
    // Disable console messages because console errors about worker script
    // fetching can be printed depending on timing of worker termination and
    // that confuses the test expectations.
    testRunner.setDumpConsoleMessages(false);
}

var worker = new Worker('resources/worker-common.js');
worker.terminate();

var worker2 = new Worker('resources/worker-common.js');
worker2.terminate();
worker2 = 0;
gc();

var worker3 = new Worker('resources/worker-common.js');
worker3.onmessage = function(evt) {
    log("FAIL");
}
worker3.postMessage("eval true");
worker3.terminate();

var worker4 = new Worker('resources/worker-common.js');
worker4.onmessage = function(evt) {
    worker4.onmessage = function() { log("FAIL"); }
    worker4.postMessage("eval true");
    worker4.terminate();
    log("Received message from worker4.");
    setTimeout("log('DONE'); if (window.testRunner) testRunner.notifyDone()", 1000);
}
worker4.postMessage("eval true");

</script>
</body>
</html>
